<template>
  <view class="tabbar">
    <view class="tabbar_list" v-for="(item,index) of tabbarList" :key="index" @tap="gotoUrl(item.path)">
      <view class="dc-jc tabbar_item" v-if="index !=2">
        <image class="img" :src="item.path == path ? item.img2:item.img"></image>
        <text :class="item.path == path ? 'selected' : ''">{{item.name}}</text>
      </view>
      <view v-else class="">
        <view class="xinzeng">
          <image class="img" :src="item.img"></image>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  import './TabBar.less'
  import Taro, {
    getCurrentInstance
  } from '@tarojs/taro';
  export default {
    setup(props, context) {
      let tabbarList = [
        {
        name: '首页',
        path: '/pages/main/main',
        img: require('@/static/tabbar/home.png'),
        img2: require('@/static/tabbar/home@selected.png')
      }, {
        name: '订单',
        path: '/pages/libo/libo',
        img: require('@/static/tabbar/libo.png'),
        img2: require('@/static/tabbar/libo@selected.png')
      }, {
        name: '+',
        path: '/pages/communic/index',
        img: require('@/static/tabbar/jia.png'),
      }, {
        name: '托管公司',
        path: '/pages/contacts/index',
        img: require('@/static/tabbar/contacts.png'),
        img2: require('@/static/tabbar/contacts@selected.png')
      }, {
        name: '我的',
        path: '/pages/mine/mine',
        img: require('@/static/tabbar/mine.png'),
        img2: require('@/static/tabbar/mine@selected.png')
      }, ]
      // tabbarList = [];
      //获取当前路由
      let {
        path
      } = getCurrentInstance().router

      //路径跳转
      const gotoUrl = (url) => {
        if (url == '/pages/communic/index') {
          Taro.redirectTo({
            url
          })
        } else {
          Taro.switchTab({
            url
          })
        }
      }
      return {
        tabbarList,
        gotoUrl,
        path
      }
    },
    onLaunch() {
      console.log(this.$router, '--this.$router.params')
    }
  }

</script>
